//
//  ViewController.m
//  打水印图像操作相关
//
//  Created by song on 15/1/28.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImage *bgimg =[UIImage imageNamed:@"scene"];
    
    //size 新图片的尺寸
    // opaque 透明度
    // 这一行代码过后，就会创建一张新的图片
    UIGraphicsBeginImageContextWithOptions(bgimg.size, NO, 0.0);
    
    [bgimg drawInRect:CGRectMake(0, 0, bgimg.size.width, bgimg.size.height)];
    
    //把水印图片缩小，然后写到图层中
    UIImage *waterimg =[UIImage imageNamed:@"QQ20140413-5"];
    CGFloat scale =0.2;
    CGFloat waterW =  waterimg.size.width *scale;
CGFloat waterH =  waterimg.size.height *scale;
    CGFloat waterX =bgimg.size.width -waterW;
    CGFloat waterY =bgimg.size.height -waterH;
    
    [waterimg drawInRect:CGRectMake(waterX, waterY, waterW, waterH)];
    
    UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    self.iconimg.image = newimg;
    
    NSData *data =UIImagePNGRepresentation(newimg);
    
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"new.png"];
    NSLog(@"%@",path);
    [data writeToFile:path atomically:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
